package at.fht.bwi.sem5;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import at.fht.bwi.sem5.view.MainMapView;

public class SplashScreen extends Activity {
	protected boolean _active = true;
	protected int _splashTime = 7000; // time to display the splash screen in ms
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.splash);
	 
	    // thread for displaying the SplashScreen
	    Thread splashTread = new Thread() {
	        @Override
	        public void run() {
	            try {
	                int waited = 0;
	                while(_active && (waited < _splashTime)) {
	                    sleep(100);
	                    if(_active) {
	                        waited += 100;
	                    }
	                }
	            } catch(InterruptedException e) {
	                // do nothing
	            } finally {
	                finish();
	                List<PackageInfo> pInfos = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
	                for (PackageInfo pInfo : pInfos) {
	                  ActivityInfo[] aInfos = pInfo.activities;
	                  if (aInfos != null) {
	                    for (ActivityInfo activityInfo : aInfos) {
	                      Log.i("ACT", activityInfo.name);
	                    }
	                  }
	                }
	                startActivity(new Intent(SplashScreen.this, AppMain.class));
	                stop();
	            }
	        }
	    };
	    splashTread.start();
	}
	
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
}
